package org.callisto.research;


import java.util.Observable;

import javax.sound.midi.ShortMessage;

import org.callisto.handlers.GUIOutputHandler;
import org.callisto.model.Keyboard;

public class Impostor extends Observable {
	
	public void run() throws Exception {
		GUIOutputHandler g = new GUIOutputHandler(null);
		Keyboard receiver = new Keyboard();
		receiver.addObserver(g);
		int time=0;
		int tickCount=0;
		int note=65;
		int status=ShortMessage.NOTE_OFF;
		int pressure=0;
		ShortMessage m = new ShortMessage();
		for (int i=0; i<20; i++) {
			String row = time + " " + tickCount + " " + note + " " + status + " " + pressure;
			tickCount=time;
			note = (int) (60 + Math.random() * 12);
			if (status==ShortMessage.NOTE_OFF) {
				status=ShortMessage.NOTE_ON;
			}
			else { 
				status=ShortMessage.NOTE_OFF;
			}
			pressure=(int) (Math.random()*127);
			m.setMessage(status, note, pressure);
			receiver.send(m, time);
			System.out.println(row);
		}
	}
	
	public void run2() {
		GUIOutputHandler g = new GUIOutputHandler(null);
		addObserver(g);
		int time=0;
		int tickCount=0;
		int note=65;
		int status=144;
		int pressure=0;
		for (int i=0; i<100; i++) {
			String row = time + " " + tickCount + " " + note + " " + status + " " + pressure;
			time += 10 + (int) (Math.random()*100);;
			tickCount=time;
			note=80;
			if (status==144) status=128; else { status=144; }
			pressure=(int) (Math.random()*127);
			System.out.println(row);
			setChanged();
			notifyObservers(row);
			try {
				Thread.sleep(100);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		// g.close();
	}
	
}